package com.maple.excel.service.impl;

import com.alibaba.excel.EasyExcel;
import com.maple.excel.entity.CustomerInfoBatch;
import com.maple.excel.listeners.CustomerInfoExcelListener;
import com.maple.excel.service.IExcelService;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.File;

/**
 * <p>服务实现类</p>
 *
 * @author maple
 */
@Service
@Slf4j
public class ExcelServiceImpl implements IExcelService {

    public Boolean createFromFile(@NonNull File file) {
        CustomerInfoExcelListener excelListener = new CustomerInfoExcelListener();
        EasyExcel.read(file)
                .autoCloseStream(true)
                .autoTrim(true)
                .head(CustomerInfoBatch.class)
                .registerReadListener(excelListener)
                .sheet(0)
                .doRead();

        return true;
    }
}
